import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import OAuthCallback from '../components/OAuthCallback.vue'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta: { 
      title: '首页' 
    }
  },
  {
    path: '/auth/google/callback',
    name: 'OAuthCallback',
    component: OAuthCallback,
    meta: { 
      title: '登录处理中...' 
    }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫：设置页面标题
router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router